package com.stx.category.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.vo.BlogVO;
import com.stx.category.service.CategoryService;
import com.stx.category.vo.CategoryVO;
import com.stx.user.vo.UserVO;

public class CategoryAction extends ActionSupport implements SessionAware {

	private Map<String, Object> session;
	private UserVO user;
	private CategoryVO categoryvo;
	private CategoryService categoryservice;
	private List<CategoryVO> categoryList;
	private List<BlogVO> blogList = new ArrayList<BlogVO>();
	private String message;

	public List<BlogVO> getBlogList() {
		return blogList;
	}

	public void setBlogList(List<BlogVO> blogList) {
		this.blogList = blogList;
	}

	private String userID;
	private String cid;

	public String listCategory() {
		categoryList = categoryservice.listCategory();
		return "listCategory";
	}

	public String getCategoryByCid() {
		categoryvo = categoryservice.getCategoryByCid(this.getCid());
		return "getCategoryByCid";
	}

	public String getCategoryByUserID() {
		categoryList = categoryservice.getCategoryByUserID(userID);
		return "getCategoryByUserID";
	}

	public String addCategory() {
		categoryvo.setUserID(((UserVO) (session.get("uservo"))).getUserid());
		categoryservice.addCategory(categoryvo);
		this.setMessage("添加成功！");
		return "listCategory";
	}

	public String deleteCategory() {
		categoryservice.deleteCategory(this.getCid());
		this.setMessage("删除成功！");
		return "listCategory";
	}

	public String editCategory() {
		categoryservice.editCategory(categoryvo.getCid(),
				categoryvo.getCategoryName());
		this.setMessage("修改成功！");
		return "editCategory";
	}

	public String listBlogBycategoryID() {
		String cid = categoryvo.getCid();
		blogList = categoryservice.listBlogBycategoryID(cid);
		return "listBlogBycategoryID";
	}

	public UserVO getUser() {
		return user;
	}

	public void setUser(UserVO user) {
		this.user = user;
	}

	public CategoryVO getCategoryvo() {
		return categoryvo;
	}

	public void setCategoryvo(CategoryVO categoryvo) {
		this.categoryvo = categoryvo;
	}

	public CategoryService getCategoryservice() {
		return categoryservice;
	}

	public void setCategoryservice(CategoryService categoryservice) {
		this.categoryservice = categoryservice;
	}

	public List<CategoryVO> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<CategoryVO> categoryList) {
		this.categoryList = categoryList;
	}

	public String getUserID() {
		return userID;
	}

	public void setUserID(String userID) {
		this.userID = userID;
	}

	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	@Override
	public void setSession(Map<String, Object> session) {

		this.session = session;

	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
